package com.yiwenup.leetcode.offer;

import java.util.Stack;

/**
 * https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/
 *
 * 执行用时：59 ms, 在所有 Java 提交中击败了55.14%的用户
 * 内存消耗：46.5 MB, 在所有 Java 提交中击败了68.36%的用户
 **/
public class No009 {

    private Stack<Integer> inStack;
    private Stack<Integer> outStack;

    public No009() {
        inStack = new Stack<>();
        outStack = new Stack<>();
    }

    public void appendTail(int value) {
        inStack.push(value);
    }

    public int deleteHead() {
        if (outStack.isEmpty()) {
            while (!inStack.isEmpty()) {
                outStack.push(inStack.pop());
            }
        }
        return outStack.isEmpty() ? -1 : outStack.pop();
    }
}
